using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Domain.Entities;
using Domain.Services;

namespace UserInterface
{
    public partial class OutputAttachment : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int attachmentId = Convert.ToInt32(Request.QueryString["id"]);
            Attachment attachment = MessageService.GetAttachment(attachmentId);

            string filePathFormat =
                ConfigurationManager.AppSettings["AttachmentsDirectory"]
                + "/"
                + ConfigurationManager.AppSettings["AttachmentFileNameFormat"];
            string filePath = String.Format(
                filePathFormat,
                attachment.Message.Id,
                attachment.LocalId
            );
            Response.ContentType = attachment.FileType;
            Response.WriteFile(filePath);
            Response.Flush();
            Response.End();
        }
    }
}
